home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / widgets / widgbase.sx < prev    next >
Encoding:
Text File  |  1995-12-06  |  5.1 KB  |  187 lines  |  [TEXT/ttxt]

  1. --<<<
  2. class ColorScheme()
  3. class variables
  4.     grayLevels:#(51,102,136,153,187,204,221)
  5.     grayBrushes
  6.     disableBrush:(new Brush color:BlackColor pattern:@grayPattern)
  7. instance variables
  8.     darkBrush1
  9.     darkBrush2
  10.     lightBrush1
  11.     lightBrush2
  12. class methods
  13.     method afterInit self #rest args -> (
  14.         apply nextMethod self args
  15.         local noOfLevels := (size ColorScheme.grayLevels)
  16.         local grayBrushes := new array initialSize:noOfLevels growable:false
  17.         for i := 1 to noOfLevels do (
  18.             local level := ColorScheme.grayLevels[i]
  19.             local brushColor := new RGBColor red:level green:level blue:level
  20.             grayBrushes[i] := new Brush color:brushColor
  21.         )
  22.         self.grayBrushes := grayBrushes
  23.         self.disableBrush.inkMode := @srcBic
  24.     )
  25. end
  26.  
  27. method init self { class ColorScheme } #rest args #key BrushIndexArray:(#(3,1,7,5))->
  28. (
  29.     self.darkBrush1 := ColorScheme.grayBrushes[BrushIndexArray[1]]
  30.     self.darkBrush2 := ColorScheme.grayBrushes[BrushIndexArray[2]]
  31.     self.lightBrush1 := ColorScheme.grayBrushes[BrushIndexArray[3]]
  32.     self.lightBrush2 := ColorScheme.grayBrushes[BrushIndexArray[4]]
  33. )
  34.  
  35. global theBaseScheme := new ColorScheme
  36. global theButtonScheme := new ColorScheme BrushIndexArray:#(3,4,7,6)
  37. global theMenuScheme := new ColorScheme BrushIndexArray:#(1,5,7,5)
  38.  
  39. class FontContext ()
  40. class vars
  41.     defaultFont
  42.     defaultSize
  43.     defaultLeading
  44.     defaultDescent
  45. instance vars
  46.     fontName,
  47.     fontSize,
  48.     leading,
  49.     descent, 
  50.     font
  51. class methods
  52.     method afterInit self #rest args -> (
  53.         apply nextMethod self args
  54.         local fontName
  55.         if (getOne (getpropertylists theSystemManager)[1] @platformNameProp = @PlatformNameMac) then (
  56.             fontName := "Chicago"
  57.             self.defaultSize := 12
  58.             self.defaultLeading := 16
  59.             self.defaultDescent := 4
  60.         ) else (
  61.             fontName := "Arial"
  62.             self.defaultSize := 14
  63.             self.defaultLeading := 15
  64.             self.defaultDescent := 2
  65.         )
  66.         self.defaultFont := new PlatformFont name:fontName
  67.     )
  68. end
  69.  
  70. method init self { class FontContext } #rest args #key fontName: \
  71.     fontSize:(FontContext.defaultSize) leading: descent:    ->
  72. (
  73.     apply nextMethod self args 
  74.  
  75.     self.fontSize := fontSize
  76.     if (fontName = unsupplied) then (
  77.         self.font := FontContext.defaultFont
  78.         self.leading := FontContext.defaultLeading
  79.         self.descent := FontContext.defaultDescent
  80.         )
  81.     else
  82.         self.font := new PlatformFont name:(fontName)
  83.     self.leading := if (leading == unsupplied) then fontSize + 3 else leading
  84.     self.descent := if (descent == unsupplied) then 3 else descent
  85. )
  86.  
  87. global theSystemFont := new FontContext
  88. global theAppFont := new FontContext fontName:"Palatino" fontSize:12 leading:14 descent:4
  89.  
  90. class Frame ()
  91. instance variables
  92.     scheme
  93.     topLeftPath
  94.     botRightPath
  95. end
  96.  
  97. method init self { class Frame } #rest args #key \
  98.             scheme: (theBaseScheme) \
  99.             boundary:(new rect x2:50 y2:50) ->
  100. (
  101.     self.scheme         := scheme
  102.     setBoundary self boundary
  103. )
  104.  
  105. method setBoundary self {class Frame} boundary -> (
  106.     local topLeftPath := new Path
  107.     self.topLeftPath := topLeftPath
  108.     MoveTo topLeftPath boundary.x1 (boundary.y2 - 1)
  109.     LineTo topLeftPath boundary.x1 boundary.y1
  110.     LineTo topLeftPath (boundary.x2 - 1) boundary.y1
  111.     local botRightPath := new Path
  112.     self.botRightPath := botRightPath
  113.     MoveTo botRightPath boundary.x1 (boundary.y2 - 1)
  114.     LineTo botRightPath (boundary.x2 - 1) (boundary.y2 - 1)
  115.     LineTo botRightPath (boundary.x2 - 1) boundary.y1
  116. )
  117.     
  118. method drawLoweredFrame self { class Frame } surface clip transform ->
  119. (
  120.     local scheme := self.scheme
  121.     local topLeftPath := self.topLeftPath
  122.     local botRightPath := self.botRightPath
  123.     translate transform 1 1
  124.     stroke surface topLeftPath clip transform scheme.darkBrush2
  125.     translate transform -2 -2
  126.     stroke surface botRightPath clip transform scheme.lightBrush2
  127.     translate transform 1 1
  128.     stroke surface topLeftPath clip transform scheme.darkBrush1
  129.     stroke surface botRightPath clip transform scheme.lightBrush1
  130. )
  131.  
  132. method drawRaisedFrame self { class Frame } surface clip transform ->
  133. (
  134.     local scheme := self.scheme
  135.     local topLeftPath := self.topLeftPath
  136.     local botRightPath := self.botRightPath
  137.     translate transform 1 1
  138.     stroke surface topLeftPath clip transform scheme.lightBrush2
  139.     translate transform -2 -2
  140.     stroke surface botRightPath clip transform scheme.darkBrush2
  141.     translate transform 1 1
  142.     stroke surface topLeftPath clip transform scheme.lightBrush1
  143.     stroke surface botRightPath clip transform scheme.darkBrush1
  144. )
  145.  
  146. function importDIB fileName #key dir:(theScriptDir) ->
  147. (
  148.     local str := getStream dir fileName @readable
  149.     local bm := importMedia theImportExportEngine str @image @DIB @Bitmap
  150.     plug str
  151.     bm
  152. )
  153.  
  154. function getDblClickTime ->
  155. (    
  156.     local plist := newPropertyList Manager
  157.     add plist @SubtypeProp @SubtypePointer
  158.  
  159.     local qlist := new LinkedList
  160.     append qlist @DoubleClickTimeProp
  161.  
  162.     local results := query theSysConfigManager  plist qlist
  163.  
  164.     local doubleClickTime := getFirst results
  165.      
  166.     if (doubleClickTime = empty) do
  167.         report ShouldntHappen #("No doubleClick value from environment.")
  168.     
  169.     doubleClickTime
  170. )
  171.  
  172. function InsetRect r xOffset yOffset todo -> (
  173.     if (todo = @mutate) then (
  174.         r.x1 := r.x1 + xOffset
  175.         r.x2 := r.x2 - xOffset
  176.         r.y1 := r.y1 + yOffset
  177.         r.y2 := r.y2 - yOffset
  178.         r
  179.     )
  180.     else (
  181.         new rect x1:(r.x1 + xOffset) x2:(r.x2 - xOffset) \
  182.             y1:(r.y1 + yOffset) y2:(r.y2 - yOffset)
  183.     )
  184. )
  185.  
  186. -->>>
  187.